package com.eeepay.eeepay_v2.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.util.Constant;
import com.eeepay.eeepay_v2.util.TimeUtils;
import com.eeepay.v2_library.ui.ABBaseActivity;
import com.eeepay.v2_library.view.LabelEditText;
import com.eeepay.v2_library.view.TitleBar;

/**
 * Created by zw on 2016/3/11 0011.
 * 代理商管理
 */
public class AgentManageActivity extends ABBaseActivity implements View.OnClickListener {

    private TitleBar titleBar;
    private LabelEditText agent_name;
    private LinearLayout two_input;
    private EditText start_date, end_date;
    private RadioGroup radioGroup;//是否包含下级
    private Button btn_confirm;

    private boolean isHaveNext = true;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_agent_manage;
    }

    @Override
    protected void initWidget() {
        titleBar = getViewById(R.id.title_bar);
        titleBar.setShowRight(View.VISIBLE);
        titleBar.setRightTextView("开设下级");
        titleBar.setRightTextColor(R.color.unify_grounding_white);

        agent_name = getViewById(R.id.agent_name);
        two_input = getViewById(R.id.create_time);
        start_date = (EditText) two_input.findViewById(R.id.input_1);
        end_date = (EditText) two_input.findViewById(R.id.input_2);
        start_date.setFocusableInTouchMode(false);
        end_date.setFocusableInTouchMode(false);

        radioGroup = getViewById(R.id.radio_group);

        btn_confirm = getViewById(R.id.btn_confirm);

    }

    @Override
    protected void eventOnClick() {
        titleBar.setRightOnClickListener(new TitleBar.RightBtnOnClickListener() {
            @Override
            public void onRightClick(View view) {
                goActivity(AgentAddStep1.class);
            }
        });
        TimeUtils.selectTime(mContext, start_date,  TimeUtils.DATE);
        TimeUtils.selectTime(mContext, end_date, TimeUtils.DATE);

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (radioGroup.getChildAt(0).getId() == checkedId) {
                    isHaveNext = true;
                } else {
                    isHaveNext = false;
                }
            }
        });
        btn_confirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_confirm:
                queryResult();
                break;

        }
    }

    private void queryResult() {
        Bundle bundle = new Bundle();
        bundle.putString(Constant.AGENT_NAME, agent_name.getEditContent());
        bundle.putString(Constant.CREATE_START_TIME, start_date.getText().toString());
        bundle.putString(Constant.CREATE_END_TIME, end_date.getText().toString());
        bundle.putBoolean(Constant.HAS_CHILD, isHaveNext);
        goActivity(AgentListActivity.class, bundle);
    }
}
